<template>
    <div class="common_pc clearfix">
        <div class="container">
            <header class="header"/>
            <section v-if="!success">
                <span class="title">彩民彩票</span>
                <p class="subtitle">送了你{{winrecords}}元彩票红包</p>
                <article>
                    <label><input class="phone" maxlength="11" v-model="phone" placeholder="输入手机号接受邀请"
                                  type="text"></label>
                    <label><input class="yzm" maxlength="6" v-model="yzm" placeholder="输入验证码" type="tel"><a
                            :class="['sendyzm' ,sending?'disable':'']"
                            @click="getyzm"
                            href="javascript:;">{{countTime}}</a></label>
                    <label class="submitbtn"><a @click="registerfn" class="submit" href="javascript:;">立即领取</a></label>
                </article>
                <span class="copyright">享更多福利   尽在彩民彩票APP</span>
            </section>
            <section class="success" v-else>
                <h5>恭喜你成功领取红包！</h5>
                <h6>1000万大奖等着您！</h6>
                <a href="http://cp.lovedou.com/cmcp/cmcp.apk" class="submit">立即下载APP</a>
                <span class="copyright">享更多福利   尽在彩民彩票APP</span>
            </section>
        </div>
        <img @load="setheight"
             src="">
    </div>

</template>

<script>
    import {Marquee, MarqueeItem, Toast} from 'vux';
    import {getMytoken, getLogintoken} from '../../services/common';
    import {nativetonative, isphone, isiOS, getUrlKey} from '../../utils/otherfn';
    import {Countdown} from '../../utils/timer';
    import {namesource, jumptype} from '../../utils/config/common';
    import axios from 'axios';
    export default {
        components: {
            Toast
        },
        data() {
            return {
                showdownbanner: true,
                phone: '',
                yzm: '',
                sending: false,
                countTime: '点击获取验证码',
                ucode: '',
                nickname: '彩民彩票',
                winrecords: '',
                success: false,
                eid: ''
            };
        },
        created() {
            this.infoload();
            this.getsharemoney();

        },
        computed: {},
        methods: {
            /**
             * 获取一些初始化信息
             */
            getsharemoney: async function () {
                const {data}= await axios.get('/hd/Handler.ashx?action=1117&params={"GroupNo":0}');
                if(data && data.code === 0) {
                    this.winrecords = data.data;
                }
                else {
                    this.$vux.toast.show({
                        type: 'text',
                        text: data.msg
                    })
                }

            },
            getmiddlepage: async function () {
                const {data}=await axios.get('/master/system/version/latest', {
                    headers: {
                        appCode: '3',
                        deviceType: isiOS() ? 'iOS' : 'Android'
                    }
                });
                if(data && data.code === 0) {
                    window.location.href = data.data.marketUrl;
                }
            },
            registerfn: async function () {
                const {phone, yzm, ucode, eid, appCode, channel}=this;
                if(!isphone(phone)) {
                    this.$vux.toast.show({
                        type: 'text',
                        text: '请输入手机号'
                    });
                    return;
                }
                if(yzm === '') {
                    this.$vux.toast.show({
                        type: 'text',
                        text: '请输入验证码'
                    });
                    return;
                }
                if(ucode === '') {
                    this.$vux.toast.show({
                        type: 'text',
                        text: '请先获取验证码'
                    });
                    return;
                }
                const {data} = await axios.get(`/user/Handler.ashx?action=703&params={"UserName":"${phone}","ValidCode":"${yzm}","RandomGuid":"${ucode}","EUserID":"${eid}"}`, {
                    headers: {
                        appCode: appCode || '3',
                        channel: channel || 'td',
                        devicecode: "",
                        devicetype: 'h5',
                        version: ''
                    }
                });
                if(data && data.code === 0) {
                    this.success = true
                }
                else {
                    this.$vux.toast.show({
                        type: 'text',
                        text: data.msg
                    });
                }
            },
            infoload: async function () {
                const eid = getUrlKey('eid');
                if(eid) {
                    this.eid = eid;
                    const {data}=await axios.get(`/user/Handler.ashx?action=708&params={"EUserID":"${eid}"}`);
                    if(!(data && data.code === 0)) {
                        this.$vux.toast.show({
                            type: 'text',
                            text: data.msg
                        })
                    } else {
                        const {NickName}=data.data;
                        this.nickname = NickName;
                    }
                }

            },
            getyzm: async function () {
                if(this.sending) {
                    return;
                }
                if(isphone(this.phone)) {
                    this.sending = true;
                    const {data}=await axios.get(`/user/Handler.ashx?action=704&params={"Mobile":"${this.phone}","TypeID":"1"}`);
                    if(data && data.code === 0) {
                        this.sending = true;
                        this.ucode = data.data;
                        let countdowns = new Countdown(59000, (data, isend)=> {
                            if(isend) {
                                this.sending = false;
                                this.countTime = `点击获取验证码`;
                            }
                            else {
                                this.countTime = `${data[0]}秒后重新获取`;
                            }
                        }, 0);
                        countdowns.start();
                    }
                    else {
                        this.$vux.toast.show({
                            type: 'text',
                            text: data.msg
                        })
                    }

                }
                else {
                    this.$vux.toast.show({
                        type: 'text',
                        text: '请输入正确手机号'
                    })
                }
            },
            jumpfn(){
                //jumptype[1]
                nativetonative(jumptype[1]);
            },
            setheight(){
                document.querySelector('.common_pc').style.minHeight = document.documentElement.clientHeight + 'px';
            }
        }
    }
</script>
<style scoped lang="less" rel="stylesheet/less">
    .common_pc {
        background: #dc1830;
        min-height: 100%;
        .bigbutton() {
            height: 68px;
            background: linear-gradient(to bottom, #ffe16e, #eac42a);
            border-bottom: 7px solid #ae6200;
            display: block;
            line-height: 68px;
            border-radius: 10px;
            border-bottom-right-radius: 16px;
            border-bottom-left-radius: 16px;
            font-size: 30px;
            color: #d13634;
        }
        .container {
            background: url(//common-1253410441.file.myqcloud.com/activityimg/20171128164918.png) no-repeat top center;
            .header {
                height: 321px;
            }
            section {
                width: 358px;
                margin: 0 auto;
                font-size: 24px;
                text-align: center;
                .title {
                    color: #f9d857;
                    display: block;
                }
                .subtitle {
                    display: block;
                    color: #fff;
                    margin-bottom: 30px;
                }
                article {
                    label {
                        display: block;
                        margin-top: 20px;
                        height: 50px;
                        &.submitbtn {
                            height: 120px;
                        }
                        input {
                            font-size: 20px;
                            width: 100%;
                            height: 50px;
                            border-radius: 6px;
                            text-indent: 24px;
                            &.yzm {
                                width: 210px;
                                float: left;
                            }
                        }
                        .sendyzm {
                            width: 133px;
                            height: 32px;
                            font-size: 18px;
                            color: #fe5454;
                            text-align: center;
                            background: linear-gradient(to bottom, #ffe16e, #eac42a);
                            border-radius: 5px;
                            float: right;
                            line-height: 32px;
                            margin-top: 10px;
                            &.disable {
                                background: #ccc;
                                color: #fff;
                            }
                        }
                        .submit {
                            .bigbutton();

                        }
                    }
                }
                .copyright {
                    font-size: 24px;
                    color: #fff;
                    padding: 0 0 100px 0;
                    display: inline-block;
                }
                &.success {
                    margin-top: 100px;
                    h5 {
                        color: #f9d857;
                        font-size: 32px;
                    }
                    h6 {
                        color: #f9d857;
                        font-size: 24px;
                        margin-bottom: 100px;
                    }
                    .submit {
                        .bigbutton();
                        display: block;
                    }
                }

            }
        }
        footer {
            position: fixed;
            bottom: 0;
            left: 0;
            width: 100%;
            height: 178px;
            background: rgba(0, 0, 0, .7);
            div {
                width: 1200px;
                display: block;
                margin: 0 auto;
                position: relative;
                i {
                    position: absolute;
                    width: 80px;
                    height: 80px;
                    right: 18px;
                    z-index: 1;
                }
                img {
                    position: relative;
                    bottom: 143px;
                }
            }

        }
    }

</style>